﻿<!--#include file="include/conn_f.asp"-->
<!--#include file="include/config.asp"-->
<!--#include file="include/crypt.asp"-->
<!--#include file="include/md5.asp"-->
<!--#include file="include/function.asp"-->
<!--#include file="top.asp"-->
<!--#include file="left.asp"-->

<div class="content">
<table width="100%" align="center">
    <tr>
        <td width="50">
        </td>
        <td>
            <center>
                <br />
                <%
orders_id=Session("itemnumber") 
check_ok=0
If orders_id="" Then	
    order_id=saferequest("order_id",1)
    order_str=saferequest("order_str",0)
    to_md5=order_id&"h79k2qpz04"
    If order_str=MD5(to_md5) Then
        orders_id=order_id
    End If
End If

If orders_id="" Then
    Response.Write "操作超时!无法自助取卡!<br />"
    Response.Write "客户服务人员会发到您填写的e-mail中,您也可以进入'我的定单'中查询!"
    Response.End
End If
sql="select *,MD5(orders_id+pay_status+432.48) as very_md5  FROM orders where orders_id="&orders_id
Set rs=conn.execute(sql)
If rs.eof Then
    Response.Write "无此定单,定单系统出现异常!"
    Response.End
Else
    goods_type=rs("goods_type")
    card_id=rs("card_1")
    card_amount=rs("card_1_amount")
    cust_id=rs("cust_id")
End If
If rs("status")<>0 Then	'不能重复取卡
    Response.Write "此定单已经处理,或者正在处理中.请进入'我的定单'查记录!"
    Response.End
End If


If rs("pay_status")=0 Then
                %>
                <script language="javascript">
                    function self_pick() {
                        window.location.reload();
                    }
                    setInterval("self_pick()", 5000);
                </script>
                <%
    Response.Write "此定单还未付款!如果你已经付款成功,请1分钟后按:<br />"
    Response.Write "<a href='processing.asp?order_id="&order_id&"&order_str="&order_str&"'>提货&gt;&gt;</a>"
Else
    'If rs("very_code")<>rs("very_md5") Then
    '	Set msg = Server.CreateOBject( "JMail.Message" )
    '	msg.Logging = true
    '	msg.silent = true
    '	msg.Charset = "gbk"
    '	msg.From = "no-reply@cardinchina.com"
    '	msg.FromName = "游龙网-警报"
    '	msg.MailServerUserName = "no-reply@cardinchina.com"
    '	msg.MailServerPassword = "max3124"
    '	msg.AddRecipient "davidxiao_1979@hotmail.com"
    '	msg.Subject = "可疑入侵!-定单:"&orders_id 
    '	msg.HTMLBody = mailbody
    '	msg.Send("mail.cardinchina.com" )		
    '	Response.Write "数据有错,请联系客户服务(BV1001)!"
    '	Response.End
    'End If
End If

sql_cust="select * from customer where cust_id="&cust_id
Set rs_cust=conn.execute(sql_cust)
If Not rs_cust.eof Then
    paypal_name=rs_cust("paypal_name")
    username=rs_cust("username")
    email=rs_cust("email")
    balance=rs_cust("balance")
    isvip=rs_cust("vip")
    isactive=rs_cust("isactive")
    buytimes=rs_cust("buytimes")
    autosend=rs_cust("autosend")
Else
    Response.Write "error!CUST_NOT_EXIST"
    Response.End
End If

If isactive=3 or isactive=2 or isactive=-1 Then	'客户帐号被封
    Response.Write "无法发卡,请和客户服务人员联系,error=102"
    Response.End
End If


If rs("pay_method")=2 Then	'paypal支付,需要核对风险
    If rs("pay_status")=3 Then
        Response.Write "付款成功!但您的付款可能需要几天才能到帐，可能因为您的付款是银行转帐！我们会在到帐后发到您的e-mail中，请注意查收，如果5天后仍然没有收到请联系我们！"
        Response.End
    ElseIf rs("pay_status")=4 or rs("pay_status")=5 Then
        Response.Write "您的付款有问题,请联系paypal或者发卡银行!！"
        Response.End
    ElseIf  rs("pay_status")=1 Then
        Response.Write "付款成功!<br />"
        If isactive=1 Then
            If autosend=1 Then
                If rs("total_amount")<rs_cust("credit_limit") Then
                    first_name=replace(rs("first_name")," ","")
                    last_name=replace(rs("last_name")," ","")
                    paypal_name=replace(paypal_name," ","")
                    If (StrComp(paypal_name,first_name&last_name,1)=0 or strcomp(last_name&first_name,paypal_name,1)=0) and len(paypal_name)>2 Then
                        check_ok=1							
                    Else
                        Response.Write "您没有使用自己的信用卡支付,需要我们人工确认发货!<br />"
                        Response.Write "请注意查收您的e-mail信箱!或者一段时间后登陆会员查'我的定单'"
                        Response.Write "<a href='http://www.cardinchina.com/buyhelp.asp' target='_blank'>如何验证?</a><br />"
                    End If
                Else
                    Response.Write "您已经超过本月信用卡消费限额,需要我们人工确认才能发货!<br />"
                    Response.Write "建议你使用银行转帐汇款方式支付(此方式没有限额)!<br />"
                    Response.Write "请注意查收您的e-mail信箱!或者一段时间后登陆会员查'我的定单'"
                End If
            Else
                Response.Write "您还不是验证会员,需要我们人工确认发货!<br />"
                Response.Write "请注意查收您的e-mail信箱!或者一段时间后登陆会员查'我的定单'"
                Response.Write "<a href='http://www.cardinchina.com/buyhelp.asp' target='_blank'>如何验证?</a><br />"
            End If
        Else
            Response.Write "信用卡(Paypal)支付,需要电话激活会员帐号才可以发货!<br />"
            Response.Write "<a href='account_active.asp' target='_blank'>现在激活帐号&gt;&gt;</a>"
        End If	
    Else
        Response.Write "付款未成功"
    End If
ElseIf rs("pay_method")=15 or rs("pay_method")=8 Then
    If isactive=1 and autosend=1 and rs("total_amount")<rs_cust("credit_limit") Then
        check_ok=1
    Else
        Response.Write "您已经超过本月信用卡消费限额,需要我们人工确认才能发货!<br />"
        Response.Write "建议你使用银行转帐汇款方式支付(此方式没有限额)!<br />"
        Response.Write "请注意查收您的e-mail信箱!或者一段时间后登陆会员查'我的定单'"
    End If	
ElseIf rs("pay_method")=7 Then
    Response.Write "您的支付已经成功,需要人工处理.请耐心等待!"
    Response.Write "<font color='red'>最近有假冒游龙网的链接,欺骗消费者购买游戏币.请仔细确认我们的网址是:www.cardinchina.com</font>"
    check_ok=0
Else
    If rs("pay_status")=3 Then
        Response.Write "付款还未完成!"
        Response.End
    End If
    If rs("pay_status")=1 Then
        check_ok=1
    End If
End If
 
Dim delived
delived=0
If check_ok=1 and rs("pay_status")=1 Then
    Message="<head><META HTTP-EQUIV='content-type' CONTENT='text/html; charset=gb2312'></head>"
    Message=Message&"谢谢您光临游龙网(<a href='http://www.cardinchina.com'>www.cardinchina.com</a>),以下是你定单信息:<br />"
    Message=Message&"定单号: "&orders_id&"<br />"
    message=Message&"支付方式:"&GetPayMethod(rs("pay_method"))&"<br />"

    If rs("pay_method")=9 Then		
        Message=Message&"本次消费金额:"&rs("total_amount")&"<br />"
        Message=Message&"您现在会员帐户余额:"&balance&"<br />"
    End If



    If goods_type=0 Then	'点卡	
        If rs("status")=0 Then
            sql="update orders set status=9 where orders_id="&orders_id
            conn.execute(sql)
        Else
            Response.Write "此定单已经处理!"
            Response.End
        End If
        g_key="850697"&g_key	
        sql_card="select a.miane,a.price,b.* from card as a left join card_infor as b on a.card_infor_id=b.card_info_id where card_id="&rs("card_1")
        Set rs_cardinfo=conn.execute(sql_card)
        Message=Message&"<table width='500' border=1 cellspacing=0><tr><td width='150'>卡名称</td><td width='350'>"&rs_cardinfo("card_name")&"</td></tr>"
        Message=Message&"<tr><td>面额</td><td>"&rs_cardinfo("miane")&"</td></tr>"
        Message=Message&"<tr><td>价格(RMB)</td><td>"&rs_cardinfo("price")&"</td></tr>"
        Message=Message&"<tr><td>购买数量</td><td>"&rs("card_1_amount")&"</td></tr>"
        Message=Message&"<tr><td>总金额(RMB)</td><td>"&rs("total_amount")
        If isvip=1 Then
            Message=Message&"&nbsp;<font color=red>(VIP价)</font>"
        End If
        Message=Message&"</td></tr></table><br />"
        Message=Message&"<font color='red'>请于购买后立即使用,发货后充值掉的卡由客户负责!</font><br />"	
        
        sql="LOCK TABLES CARD_DETAIL WRITE"
        conn.execute sql
        sql="select card_detail_id,username,password from card_detail where status=1 and card_id="&rs("card_1")&" order by card_detail_id asc"
        Set rs2=conn.execute(sql)	'卡的种类和使用信息
        count=0	
        If Not rs2.eof Then	'发卡
            Message=Message&"以下是卡号和密码:<br />"
            rs2.movefirst	
            For i=1 to rs("card_1_amount")
                If Not rs2.eof Then
                    count=count+1
                    Message=Message&"<table border=1 cellspacing=0 width='300'><tr><td>卡号(序列号)</td><td>"&rs2("username")&"</td></tr>"
                    Message=Message&"<tr><td>密码(充值密码)</td><td>"&DeCrypt(rs2("password"))&"</td></tr></table><br />"
                    sql="update card_detail set status=0,orders_id="&orders_id&" where card_detail_id="&rs2("card_detail_id")
                    conn.execute sql
                    rs2.movenext				
                End If
            Next
        End If
        sql="UNLOCK TABLES"
        conn.execute sql

        If rs("card_1_amount")=count Then
            sql="update orders set status=1,delived=1,delived_amount="&count&",process_time=now() where orders_id="&orders_id
            conn.execute(sql)
            delived=1
        Else
            If count>0 Then
                sql="update orders set delived=2,delived_amount="&count&",process_time=now() where orders_id="&orders_id
                conn.execute(sql)
            End If
            Message=Message&"无法取得足够的卡,可能是卡库存不足.我们将尽快补齐并发到您的信箱中，请注意查收您的e-mail,或直接和我们联系!"
        End If
        sql="update card set sold=sold+"&count&",amount=amount-"&count&" where card_id="&rs("card_1")
        conn.execute sql

        Message=Message&"<br /><table width='500' border=1 cellspacing=0><tr><td width='50'>卡介绍:</td><td width='450'>"&rs_cardinfo("feeratio")&"</td></tr>"
        Message=Message&"<tr><td>使用说明:</td><td>"&rs_cardinfo("descript")&"</td></tr></table>"

    ElseIf goods_type=1	Then	'直充	

        sql="select * from charge_detail where orders_id="&orders_id
        Set rs_charge=conn.execute(sql)
        If Not rs_charge.eof Then
            charge_detail_id=rs_charge("charge_id")
            game_account=rs_charge("game_account")
            charge_method=rs_charge("charge_method")
            server_ID=rs_charge("server_ID")
        End If

        sql_card="select * from card where card_id="&rs("card_1")
        Set rs_cardinfo=conn.execute(sql_card)
        esales_value=rs_cardinfo("esales_value")
        
        Dim return_string,charged_card_amount
        select case card_id
        case 295,306,270,271,272,316,651,652,653
                %>
                <!--#include file="QQ_charge_function.asp"-->
                <%
            sql="update orders set status=2,process_time=now() where orders_id="&orders_id
            conn.execute(sql)
            charge_status=qq_do_charge(orders_id,card_id,charge_method,game_account,card_amount)

            If charge_status=1 and charged_card_amount=card_amount Then
                sql="update orders set status=1,delived=1,delived_amount="&charged_card_amount&",process_time=now() where orders_id="&orders_id
                conn.execute(sql)
                Response.Write "自动充值成功!您购买的商品已经充到你指定的QQ号码上<br />"
                sql="update charge_detail  set sent_place='qb.qq.com',sent_status=1  where charge_id="&charge_detail_id
                conn.execute(sql)
                sql="update card set sold=sold+"&card_amount&" where card_id="&card_id
                conn.execute sql			

                '更新实时库存和销量情况
                sql="select stock_live from esales_stock where esales_id=2"
                Set rs_esales_stock=conn.execute(sql)
                If Not rs_esales_stock.eof Then
                    esales_stock_live=rs_esales_stock("stock_live")
                End If
                sql="update esales_stock set stock_live=stock_live-"&esales_value*charged_card_amount&",sold=sold+"&esales_value*charged_card_amount&" where esales_id=2"
                conn.execute sql
                sql="insert into esales_stock_log(log_time,esales_id,update_id,amount,stock_live,"
                sql=sql&"orders_id,charge_account) values(now(),2,1,-"&esales_value*charged_card_amount
                sql=sql&","&esales_stock_live&",'"&orders_id&"','"&game_account&"')"
                conn.execute sql

                delived=1
            ElseIf charge_status=0 Then
                Response.Write "服务器无响应,请查一下您的QQ帐号是否已经充上,如果没有充上,请联系客户工作人员."
            Else
                If charged_card_amount=0 Then
                    sql="update orders set status=0,process_time=now(),memo_cs='系统1:自动充值失败!"&return_string&"' where orders_id="&orders_id
                    conn.execute(sql)
                    Response.Write "<font color='red'>自动充值失败!<br />"
                    Response.Write "工作人员会为您手工充值.</font><br />"						
                    Response.End
                Else	'部分充值成功
                    sql="update orders set status=2,delived=2,delived_amount="&charged_card_amount&",process_time=now(),memo_cs='系统1:已经部分充值!充值张数:"&charged_card_amount&",错误原因:"&return_string&"' where orders_id="&orders_id
                    conn.execute(sql)
                    Response.Write "<font color='red'>已经部分充值!<br />"
                    Response.Write "充值张数:"&charged_card_amount&",,剩下的会为您手工充值.</font><br />"

                    '更新实时库存和销量情况
                    sql="select stock_live from esales_stock where esales_id=2"
                    Set rs_esales_stock=conn.execute(sql)
                    If Not rs_esales_stock.eof Then
                        esales_stock_live=rs_esales_stock("stock_live")
                    End If
                    sql="update esales_stock set stock_live=stock_live-"&esales_value*charged_card_amount&",sold=sold+"&esales_value*charged_card_amount&" where esales_id=2"
                    conn.execute sql
                    sql="insert into esales_stock_log(log_time,esales_id,update_id,amount,stock_live,"
                    sql=sql&"orders_id,charge_account) values(now(),2,1,-"&esales_value*charged_card_amount
                    sql=sql&","&esales_stock_live&",'"&orders_id&"','"&game_account&"')"
                    conn.execute sql
                End If			
            End If
        case 407,414,434,476,490,512,515,589,623  
                %>
                <!--#include file="wanmei_charge_function.asp"-->
                <%
            sql="update orders set status=2,process_time=now() where orders_id="&orders_id
            conn.execute(sql)
            charge_status=wanmei_do_charge(orders_id,card_id,game_account,server_ID,card_amount)
            If charge_status=1 and charged_card_amount=card_amount Then
                sql="update orders set status=1,delived=1,delived_amount="&charged_card_amount&",process_time=now() where orders_id="&orders_id
                conn.execute(sql)
                Response.Write "<font color='green'>自动充值成功!</font><br />"
                sql="update charge_detail  set sent_place='esales.wanmei.com',sent_status=1  where charge_id="&charge_detail_id
                conn.execute(sql)
                sql="update card set sold=sold+"&card_amount&" where card_id="&card_id
                conn.execute sql

                '更新实时库存和销量情况
                    sql="select stock_live from esales_stock where esales_id=3"
                    Set rs_esales_stock=conn.execute(sql)
                    If Not rs_esales_stock.eof Then
                        esales_stock_live=rs_esales_stock("stock_live")
                    End If
                    sql="update esales_stock set stock_live=stock_live-"&esales_value*charged_card_amount&",sold=sold+"&esales_value*charged_card_amount&" where esales_id=3"
                    conn.execute sql
                    sql="insert into esales_stock_log(log_time,esales_id,update_id,amount,stock_live,"
                    sql=sql&"orders_id,charge_account) values(now(),3,1,-"&esales_value*charged_card_amount
                    sql=sql&","&esales_stock_live&",'"&orders_id&"','"&game_account&"')"
                    conn.execute sql

                    delived=1
            ElseIf charge_status=0 Then
                Response.Write "<font color='red'>已提交,但服务器无响应,需要核查是否已经充上.</font>"
                Response.End
            Else
                If charged_card_amount=0 Then
                    sql="update orders set status=0,process_time=now(),memo_cs='系统1:自动充值失败!"&return_string&"' where orders_id="&orders_id
                    conn.execute(sql)
                    Response.Write "<font color='red'>自动充值失败!<br />"
                    Response.Write "工作人员会为您手工充值.</font><br />"						
                    Response.End
                Else	'部分充值成功
                    sql="update orders set status=2,delived=1,delived_amount="&charged_card_amount&",process_time=now(),memo_cs='系统1:已经部分充值!充值张数:"&charged_card_amount&",错误原因:"&return_string&"' where orders_id="&orders_id
                    conn.execute(sql)
                    Response.Write "<font color='red'>已经部分充值!<br />"
                    Response.Write "充值张数:"&charged_card_amount&",剩下的会为您手工充值.</font><br />"

                    '更新实时库存和销量情况
                        sql="select stock_live from esales_stock where esales_id=3"
                        Set rs_esales_stock=conn.execute(sql)
                        If Not rs_esales_stock.eof Then
                            esales_stock_live=rs_esales_stock("stock_live")
                        End If
                        sql="update esales_stock set stock_live=stock_live-"&esales_value*charged_card_amount&",sold=sold+"&esales_value*charged_card_amount&" where esales_id=3"
                        conn.execute sql
                        sql="insert into esales_stock_log(log_time,esales_id,update_id,amount,stock_live,"
                        sql=sql&"orders_id,charge_account) values(now(),3,1,-"&esales_value*charged_card_amount
                        sql=sql&","&esales_stock_live&",'"&orders_id&"','"&game_account&"')"
                        conn.execute sql
                End If
            End If
        CASE Else
            Response.Write "您的款已经收到，我们会尽快将卡充值到您的游戏帐号.<br />"
            Response.Write "由于是手工充值你需要等待一段时间(大约半小时)."
        end SELECT		
        
    ElseIf goods_type=6	Then	'游戏币
        Response.Write "您的款已经收到，我们会尽快将游戏币通过游戏中的信箱系统,发送到你指定的游戏角色号上，由于是手工充值你需要等待一段时间"
        Response.End	'程序结束
    ElseIf goods_type=2 Then
        Response.Write "您的款已经收到，我们会尽快为您汇款!"
    ElseIf goods_type=4 Then
        Response.Write "您的款已经收到，密码保护卡人工处理后会发给你,您也可以登陆网站查定单详情!"
    ElseIf  goods_type=5 Then		'储值
        If rs("status")=0 Then
            sql="update orders set status=9,process_time=now() where orders_id="&orders_id
            conn.execute(sql)
        Else
            Response.Write "此定单已经处理!"
            Response.End
        End If
        sql="update customer set balance=balance+"&rs("total_amount")&",very_code=MD5(cust_id+balance+325.61) where cust_id="&cust_id
        conn.execute sql
        sql_balance="select balance from customer where cust_id="&cust_id
        Set rs_balance=conn.execute(sql_balance)
        newbalance=rs_balance("balance")
        sql="insert into balance_detail(orders_id,cust_id,amount,deposit_type,balance,deposit_method,status,deposit_time,md5) values("
        sql=sql&orders_id&","&cust_id&","&rs("total_amount")&",1,"&newbalance&","&rs("pay_method")&",1,now(),' ')"
        conn.execute sql
        sql="update orders set status=1,delived=1,process_time=now() where orders_id="&orders_id
        conn.execute(sql)
        Message=Message&"您的款已经成功储值到您的会员帐号:<font color=red>"&username&"</font><br />"
        Message=Message&"本次储值金额:"&rs("total_amount")&"<br />"
        Message=Message&"您帐户新的余额:"&newbalance&"<br />"
        delived=1
    End If
    Response.Write Message	
    Message=Message&"请不要回复本邮件,此邮件是系统发信,联系客户服务请发e-mail到:cs@cardinchina.com"
    mailbody=Message	
    '通过邮件发送到用户
    'Dim MailObject 
    'Set MailObject = Server.CreateObject("CDONTS.NewMail") 
    'MailObject.From="no-reply@cardinchina.com"	'发件邮址 
    'MailObject.To=email '收件人 
    'MailObject.Subject="游龙网发货通知-定单号:"&orders_id 
    'MailObject.Body=mailbody 
    'MailObject.MailFormat = 0
    'MailObject.BodyFormat = 0
    'MailObject.Send '发送邮件 


    Set msg = Server.CreateOBject( "JMail.Message" )
    msg.Logging = true
    msg.silent = true
    msg.Charset = "utf-8"
    msg.From = "no-reply@cardinchina.com"
    msg.FromName = "游龙网"
    msg.MailServerUserName = "no-reply@cardinchina.com"
    msg.MailServerPassword = "max3124"
    msg.AddRecipient email
    msg.Subject = "游龙网发货通知-定单号:"&orders_id
    msg.HTMLBody = mailbody
    msg.Send("mail.cardinchina.com") 
    Set msg = Nothing
End If
If delived=1 and (rs("pay_method")=2 or rs("pay_method")=1 or rs("pay_method")=8 or rs("pay_method")=10 or rs("pay_method")=15) Then
    sql="update customer set  buytimes=buytimes+"&int(rs("total_amount"))&",available_bonus=available_bonus +"&int(rs("total_amount"))
    If (rs("pay_method")=2 or rs("pay_method")=8 or rs("pay_method")=15) Then
        sql=sql&",credit_limit=credit_limit-"&int(rs("total_amount"))
    End If
    sql=sql&" where cust_id="&cust_id
    conn.execute sql
End If					
                %>
                <td width="50">
                </td>
    </tr>
</table>
</div>
<!--#include file="bottom.asp"-->
